<?php
//打赏管理
namespace app\admin\controller;
use think\Db;
class Reward extends Base {

    public function index(){
        if(request()->isAjax()){
            extract(input());
            $map =array();
            $page = input('page') ? input('page'):1;
            $limit = input("limit")?input("limit"):10;// 获取总条数;
            if(isset($key)&&$key!="")
            {
                $map['a.donate_number'] = ['like',"%" . $key . "%"];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end=="")
            {
                $map['a.pay_time'] = ['>= time',$start];
            }
            if(isset($end)&&$end!=""&&isset($start)&&$start=="")
            {
                $map['a.pay_time'] = ['<= time',$end];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end!="")
            {
                $map['a.pay_time'] = ['between time',[$start,$end]];
            }
            $map['a.cate']  = 2;
            $map['a.donate_status']  = 1;
            $count = Db::table('up_activity_order')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.user_id','left')
                ->where($map)
                ->count();
            $list = Db::table('up_activity_order')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.user_id','left')
                ->where($map)
                ->field('a.*,uuu.user_username')
                ->order('a.pay_time desc')
                ->page($page, $limit)
                ->select();//计算总页面
            return json(['code'=>0,'msg'=>'','count'=>$count,'data'=>$list]);

        }
        return $this->fetch();
    }
}